package leetcode.problems;

/**
 * Created by gmwang on 2018/3/22
 */
public class _0322JudgeRouteCircle {
    /**
     * Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.
     The move sequence is represented by a string. And each move is represent by a character. The valid robot moves are R (Right), L (Left), U (Up) and D (down). The output should be true or false representing whether the robot makes a circle.
     Example 1:
     Input: "UD"
     Output: true
     Example 2:
     Input: "LL"
     Output: false
     最初，位置（0,0）处有一个机器人。给出它的一系列动作，判断这个机器人是否有一个圆圈，这意味着它移回到原来的位置。

     移动顺序由一个字符串表示。而每一个动作都是由一个人物来表现的。有效的机器人移动是R（右），L（左），U（上）和D（下）。输出应该是真或假，表示机器人是否做出圆圈。

     例1：
     输入： “UD”
     输出： true
     例2：
     输入： “LL”
     输出：错误
     */
    public static boolean judgeCircle(String moves) {
        Boolean flag = false;
        int up =0,down =0,left =0,right =0;
        for (char move:moves.toCharArray()) {
            if(move == 'U') up++;
            if(move == 'D') down++;
            if(move == 'L') left++;
            if(move == 'R') right++;
        }
        if(left == right && up == down) flag = true;
        return flag;
    }

    public static void main(String[] args) {
        System.out.println(judgeCircle("LL"));
    }
}
